//Given an integer numRows, return the first numRows of Pascal's triangle. 
//
// In Pascal's triangle, each number is the sum of the two numbers directly abov
//e it as shown: 
//
// 
// Example 1: 
// Input: numRows = 5
//Output: [[1],
//        [1,1],
//       [1,2,1],
//      [1,3,3,1],
//     [1,4,6,4,1]]
// Example 2: 
// Input: numRows = 1
//Output: [[1]]
// 
// 
// Constraints: 
//
// 
// 1 <= numRows <= 30 
// 
// Related Topics 数组 
// 👍 490 👎 0


package leetcode.editor.cn;

import java.util.ArrayList;
import java.util.List;

//Java：Pascal's Triangle
 class P118PascalsTriangle {
    public static void main(String[] args) {
        Solution solution = new P118PascalsTriangle().new Solution();
        // TO TEST
    }

    //leetcode submit region begin(Prohibit modification and deletion)
    class Solution {
        public List<List<Integer>> generate(int numRows) {
            List<List<Integer>> result = new ArrayList<>();
            for (int i = 0; i < numRows; i++) {
                List<Integer> child = new ArrayList<>();
                if (result.isEmpty()) {
                    child.add(1);
                } else {
                    List<Integer> father = result.get(i - 1);
                    child.add(1);
                    for (int j = 1; j < father.size(); j++) {
                        child.add(father.get(j - 1) + father.get(j));
                    }
                    child.add(1);

                }
                result.add(child);
            }
            return result;

        }
        public  List<List<Integer>> generateElse(int numRows) {
            List<List<Integer>> lllist = new ArrayList<>();
            for (int i = 0; i < numRows; i++) {
                List list = new ArrayList();
                int len = i + 1;
                for (int j = 0; j < len; j++) {
                    if (j == 0 || j == len - 1) {
                        list.add(1);
                    } else {
                        List<Integer> list1 = lllist.get(i - 1);
                        list.add(list1.get(j) + list1.get(j - 1));

                    }

                }
                lllist.add(list);
            }

            return lllist;
        }
    }
//leetcode submit region end(Prohibit modification and deletion)

}